package com.service.impl;

import com.domain.UserInfo;
import com.repository.UserInfoRepository;
import com.service.IUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserInfoServiceImpl implements IUserInfoService {
    @Autowired
    private UserInfoRepository repository;
    @Override
    public void save(UserInfo userInfo) {
        userInfo.setId(null);
        repository.save(userInfo);
    }
    @Override
    public void update(UserInfo userInfo) {
        repository.save(userInfo);
    }
    @Override
    public void delete(String id) {
        repository.deleteById(id);
    }
    @Override
    public UserInfo get(String id) {
        return repository.findById(id).orElse(null);
    }
    @Override
    public List<UserInfo> list() {
        return repository.findAll();
    }

    //检查手机号码是否存在
    @Override
    public boolean checkPhone(String phone) {
        UserInfo userInfo = repository.findByPhone(phone);
        return userInfo == null;
    }
}